home *** CD-ROM | disk | FTP | other *** search
- /* Copyright, 1990, Regents of the University of Colorado */
- /* This program uses a red-black algorithm to solve Poisson's equation,
- * given rectangular boundary conditions. It uses the example package
- * of routines for dealing with uneven mappings in map.c. */
-
- /* Defined size of the processor grid */
- #define P1 4
- #define P2 4
-
- /* Defined size of the data grid */
- #define N1 8
- #define N2 8
-
- /* Define the mapping for the data */
- map FivePoint = [block overlap 1,1][block overlap 1,1];
-
- environment node[P1:id1][P2:id2] {
-
- #include "../inc/map.c"
-
- composite iterate (a, in iter)
-
- double distributed a[N1][N2] map FivePoint;
- int iter;
-
- {
- map_var a1, a2; /* Hold the looping information for this */
- int q; /* Looping variable */
- int i, j; /* Index variables */
-
- /* Set up the home variables for a */
- set_map_var (N1, P1, id1, 1, 1, &a1);
- set_map_var (N2, P2, id2, 1, 1, &a2);
- limit_map_var (1, N1 - 2, &a1);
- limit_map_var (1, N2 - 2, &a2);
-
- /* Go around iter times */
- for (q = 0; q < iter; q++) {
-
- /* Update the information, if not the first iteration */
- if (q > 0) {
-
- /* Send the home copy */
- a[<a1.left,a1.right>][<a2.left,a2.right>]# =
- a[<a1.left,a1.right>][<a2.left,a2.right>];
-
- /* Receive the data */
- a[<a1.lover,a1.rover>][<a2.lover,a2.rover>] =
- a[<a1.lover,a1.rover>][<a2.lover,a2.rover>]#;
- }
-
- /* Now, let's recompute the even entries */
- for (i = a1.left; i <= a1.right; i++)
- for (j = ((((i + a2.left) % 2) == 1) ? 1 : 0) + a2.left;
- j <= a2.right; j += 2)
-
- /* Do the recomputation */
- a[i][j] = (a[i-1][j] + a[i+1][j] + a[i][j-1] + a[i][j+1]) / 4;
-
- /* Redistributed the information */
- a[<a1.left,a1.right>][<a2.left,a2.right>]# =
- a[<a1.left,a1.right>][<a2.left,a2.right>];
-
- a[<a1.lover,a1.rover>][<a2.lover,a2.rover>] =
- a[<a1.lover,a1.rover>][<a2.lover,a2.rover>]#;
-
- /* Now, let's recompute the odd entries */
- for (i = a1.left; i <= a1.right; i++)
- for (j = ((((i + a2.left) % 2) == 0) ? 1 : 0) + a2.left;
- j <= a2.right; j += 2)
-
- /* Do the recomputation */
- a[i][j] = (a[i-1][j] + a[i+1][j] + a[i][j-1] + a[i][j+1]) / 4;
- }
- }
- }
- environment host {
-
- void main () {
-
- double m[N1][N2]; /* The array of data */
- int i, j; /* Index variables */
- int iter = 100; /* Fake iteration variable */
-
- /* Set up the data in m */
- for (i = 0; i < N1; i++)
- for (j = 0; j < N2; j++)
- m[i][j] = (i + 1) * (j + 1);
- for (i = 1; i < N1 - 1; i++)
- for (j = 1; j < N2 - 1; j++)
- m[i][j] = 0;
-
-
- /* Do the computation */
- printf ("Running...\n");
- iterate (m[][], iter)#;
-
- /* Print out the results */
- for (i = 0; i < N1; i++) {
- for (j = 0; j < N2; j++)
- printf ("%6.2f ", m[i][j]);
- printf ("\n");
- }
- printf ("\nThat's it!\n");
- }
- }
-